﻿

//Login GenShell.The common entry of PEBank
//Global var defined here
var GenShellLogoutFlag = false;


//Variables used by GenIndex.aspx begin
var TokenArray = new Array();
var LoginRecordArray = new Array();

var Default_DialogFeatures = "dialogHeight: 550px; dialogWidth: 750px;  edge: Raised; center: Yes; help: Yes; resizable: No; status: No;";
var Custom_DialogFeatures = null;

var Default_NewWindowFeatures = "status=no,scrollbars=yes,width=750,height=550,top=0,left=0";
var Custom_NewWindowFeatures = null;

var Default_FormTarget = "mainWorkArea";
var MainWorkAreaIFrame = null;
var Custom_FormTarget = null;
//Variables used by GenIndex.aspx end




/*set features for Modal/Modeless dialog*/
function setDialogFeatures(features)
{
	Custom_DialogFeatures = features;
}

function getDialogFeatures()
{
	if(Custom_DialogFeatures == null)
	{
		return Default_DialogFeatures;
	}
	else
	{
		var retFeatures = Custom_DialogFeatures;
		Custom_DialogFeatures = null;
		return retFeatures;
	}
}

/*set features for window.open(...)*/
function setNewWindowFeatures(features)
{
	NewWindowFeatures = features;
}

function getNewWindowFeatures()
{
	if(Custom_NewWindowFeatures == null)
	{
		return Default_NewWindowFeatures;
	}
	else
	{
		var retFeatures = Custom_NewWindowFeatures;
		Custom_NewWindowFeatures = null;
		return retFeatures;
	}
}

/*set target for DynaForm*/
function setFormTarget(target)
{
	Custom_FormTarget = target;
}

function getFormTarget()
{
	if(Custom_FormTarget == null)
	{
		return Default_FormTarget;
	}
	else
	{
		var retTarget = Custom_FormTarget;
		Custom_FormTarget = null;
		return retTarget;
	}
}



/*Trigger trans function from menu,link,etc.. Mainly used by GenIndex.aspx
* params:
*	param1: authName, could be CBANK_PB,CBANK_CREDITCARD,CBANK_INVEST,CBANK_USER
*	param2: funcName, the function to be fired
*	param3: target of the function result. could be: FORM,MODAL_DIALOG,MODELESS_DIALOG
*	paramn: other param transfer to function,format:paramName=paramValue
*   更新说明（2008-11-18）：大众版导航功能需要切换菜单和记录历史操作，由于CallFunc并不支持，故
*   使用CallFuncEx2替换CallFunc的功能，保留CallFunc以提供向下兼容功能（防备万一），所有后续开发
*   应使用CallFuncEx2代替CallFunc。
*   CallFuncEx2对CallFunc做了包装，以提供切换菜单和记录历史操作的功能，因此不能删除CallFunc函数
*/
function CallFunc(funcName,targetType,target)
{
	if(window.event)
	{
		window.event.returnValue = false;
	}
	
	//build action for dynaForm
	var action =  funcName;
	//alert(action);
	var dynaForm = new DynaForm("GenForm");
	dynaForm.setAction(action);

	if(arguments.length >= 5)
	{
		for(var i=4; i<arguments.length; i++)
		{
			var args = arguments[i].split("=");
			dynaForm.addHidden(args[0],args[1]);
		}
	}
	//dynaForm.enableDebug();
	if(targetType == "MODAL_DIALOG")
	{
		g_ModalDialogClick = true;
		return true;
	}
	else if(targetType == "MODELESS_DIALOG")
	{
		return true;
	}
	else
	{
		if (target == null)
		{
			target = getFormTarget();
		}

		if(target == Default_FormTarget)
		{
			//if(MainWorkAreaIFrame)
			
				//mainWorkArea.document.write("<style TYPE='text/css'>.mycontent {font: 9pt/14pt '宋体';}</style>");
				mainWorkArea.document.write("<body style='margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;'><table height=300 width=100% align=center><tr><td height=100% width=100% align=center><font size=2pt>\u6b63\u5728\u52a0\u8f7d\u6570\u636e\uff0c\u8bf7\u7a0d\u5019 ... ...</font></tr></td></table></body>");
				//mainWorkArea.document.close();
				//return;

		}

		dynaForm.setFeatures(getNewWindowFeatures());
		dynaForm.setTarget(target);
		//dynaForm.enableDebug();
		dynaForm.submit();
		return true;
	}
}

//request from shell to other transserver by xmlhttp
function CallFuncEx(authName,funcName,prid,boolAsync,callBackFunc)
{
	//alert("in callfuncex");
	if(window.event)
	{
		window.event.returnValue = false;
	}

	var loginRecord = LoginRecordArray[authName]
	if(loginRecord == undefined)
	{//not login yet, forward user to login transaction server
		//If the authname is valid, comment this check when needed
		if(!IsValidAuthName(authName))
		{
			//alert("!IsValidAuthName(authName)");
			return false;
		}
		if(ConnectTranServer(authName,GenShell_ClientNo,TokenArray,LoginRecordArray))
		{
			loginRecord = LoginRecordArray[authName];
		}
		else
		{
			alert("ConnectTranServer failed:"+authName);
			return false;
		}
	}

	//build action for dynaForm
	var action = loginRecord.serverUrl + funcName;				
	var hostPkg = new HostPkg(prid);
	if(arguments.length >= 6)
	{
		for(var i=5; i<arguments.length; i++)
		{
			var args = arguments[i].split("=");
			hostPkg.AddParam(args[0],args[1]);
		}
	}
	hostPkg.AddParam("ClientNo",loginRecord.clientNo);

	var webSvrCom = new WebSvrCom(action);
	webSvrCom.WSCSetAsync(boolAsync);
	webSvrCom.WSCClearHostPkg();
	webSvrCom.WSCAddHostPkg(hostPkg);
	webSvrCom.WSCSendRequest(callBackFunc);
	//alert("exit ok");
	
	var loginRecord = LoginRecordArray["CBANK_SHELL"];
}


var g_currMenuType = '';
function CallFuncEx2(menuType,authName,funcName,targetType,target)
{
	if(window.event)
	{
		window.event.returnValue = false;
	}
	var sJsonCardInfo = document.getElementById("CardsInfoForType").value;
	var jsonCardInfo = null;
	try{
		jsonCardInfo = eval("("+sJsonCardInfo +")");
	}catch(e){
		jsonCardInfo = null
	}
	if(jsonCardInfo!=null && menuType!=null)
	{
		if(jsonCardInfo[menuType]!=true)
		{
			if(menuType=="A")
				alert("对不起，您没有绑定一卡通，无法使用相关功能！");
			else if(menuType=="B")
				alert("对不起，您没有绑定存折，无法使用相关功能！");
			else if(menuType=="C_A")
				alert("对不起，您没有绑定信用卡，无法使用相关功能！");
			else if(menuType=="D")
				alert("您需要使用一网通用户后才能使用相关功能！");
			else
				alert("您暂时无法使用当前功能！");
			return;
		}
	}else
	{
		return;
	}

	try{
		TryAddHistoryOpFromCallFunc(arguments);
	}catch(e){}

	var args = new Array();
	for(var i=1;i<arguments.length;i++)
	{
		args.push(arguments[i]);
	}
	var r = CallFunc.apply(this,args);
	//args.
	//arguments
	if(r)
	{
		if(jsonCardInfo['D']==null)
			return;
		if(g_currMenuType!=menuType)
		{
			switchImg(menuType);
			switchMenuOnly(menuType);
			
		}
	}
}

function GenSendXmlRequest(data2Send,svrUrl)
{
	var dynaXmlhttp = new DynaXmlHttp();
	dynaXmlhttp.addParams(data2Send);
	dynaXmlhttp.setXmlHttpObj(xmlHttpObj);
	dynaXmlhttp.setAction(svrUrl);
	//dynaXmlhttp.enableDebug();
	if(dynaXmlhttp.send())
	{
		//alert("dd:"+dynaXmlhttp.getResponseHeader("Content-Type"));
	    return dynaXmlhttp.getResponseText();
	}
	else
	{
		//alert("Fatal error occurs! Send XmlRequest Failed!");
		alert("\u83b7\u53d6\u83dc\u5355\u6570\u636e\u5931\u8d25\uff0c\u8bf7\u6309F5\u5237\u65b0\u60a8\u7684\u9875\u9762!");
		return false;
	}
}

/*
if(window.onload)
{
	alert("document.body");
}
else
{
	window.onload=SetGenStyle;
}

alert(window.document.body.onload);
*/

function SetGenStyle(styleTitle,theDocument)
{
	if(theDocument)
	{
	}
	else
	{
		theDocument = document;
	}
	var GenStyleCookie = new Cookie(theDocument, "Cmb_GenServer_Style", 24*365*10);
	if(styleTitle)
	{
	}
	else
	{
		if(GenStyleCookie.load())
		{
			styleTitle = GenStyleCookie.style;
		}
		else
		{
			styleTitle = "default";
		}
	}

	var links = theDocument.getElementsByTagName("link");
	for(i=0; links[i]; i++)
	{
		if(links[i].getAttribute("rel").indexOf("style") != -1&&links[i].getAttribute("title"))
		{
			links[i].disabled = true;
			if(links[i].getAttribute("title").indexOf(styleTitle) != -1)
				links[i].disabled = false;
		}
	}
	//alert(styleTitle);
	GenStyleCookie.style = styleTitle;
	GenStyleCookie.store();
}
